package de.sup.scs.prototyp.client.ui.main;

import com.google.gwt.dom.client.Style;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewImpl;

public class MainPageView extends ViewImpl implements MainPagePresenter.MyView{

    @UiField
    LayoutPanel panel;

    private Widget curContent;
    private Widget curTitle;
    private Widget curFooter;

    public interface MyUiBinder extends UiBinder<Widget, MainPageView> {}

    @Inject
    public void MainPageView(final MyUiBinder binder){
        binder.createAndBindUi(this);
    }

    @Override
    public void setInSlot(Object slot, Widget content) {


        // -- TITLE
        if (slot.equals(MainPagePresenter.TITLE)){

            if (curTitle != null){
                curTitle.removeFromParent();
            }

            panel.add(content);
            panel.setWidgetLeftWidth(content, 2, Style.Unit.PX,  1276, Style.Unit.PX);
            panel.setWidgetTopHeight(content, 2, Style.Unit.PX,  80, Style.Unit.PX);

            curTitle = content;
        }

        // -- CONTENT
        if (slot.equals(MainPagePresenter.CONTENT)){

            if (curContent != null){
                curContent.removeFromParent();
            }

            panel.add(content);
            panel.setWidgetLeftWidth(content, 2, Style.Unit.PX,  1276, Style.Unit.PX);
            panel.setWidgetTopHeight(content, 84, Style.Unit.PX,  554, Style.Unit.PX);

            curContent = content;
        } else {
            super.setInSlot(slot, content);
        }

        // -- FOOTER
        if (slot.equals(MainPagePresenter.FOOTER)){

            if (curFooter != null){
                curFooter.removeFromParent();
            }

            panel.add(content);
            panel.setWidgetLeftWidth(content, 2, Style.Unit.PX,  1276, Style.Unit.PX);
            panel.setWidgetTopHeight(content, 638, Style.Unit.PX,  80, Style.Unit.PX);

            curFooter = content;
        }
    }

    @Override
    public Widget asWidget() {
        return panel;
    }
}
